*THIS FILE GENERATES VARIABLES FOR USE IN SURVEY ANALYSIS


use "SHG Survey.dta", clear


gen Aft=(TYPE==2) 
label var Aft "Post intervention"
gen SewaV=(avs==1)
label var SewaV "SEWA Village"
gen SewaVXAft=Aft*SewaV
label var SewaVXAft "SEWA village post intervention"
gen SHG=(q81==1)
label var SHG "Participates in group activities"


gen Treat_before=(SewaV==1) if Aft==0
gen Treat_after=(SewaV==1) if Aft==1


*Knowledge of reporting

gen know_water = (q312co_1==1|q312co_1==3|q312co_1==4|q312co_1==6|q312co_1==9|q312co_1==11|q312co_1==12)
gen know_roads = (q312co_2==1|q312co_2==3|q312co_2==4|q312co_2==9|q312co_2==12|q312co_2==16|q312co_2==21)
gen know_elec = (q312co_3==1|q312co_3==3|q312co_3==4|q312co_3==8|q312co_3==9|q312co_3==10|q312co_3==12)
gen know_educ = (q312co_4==1|q312co_4==2|q312co_4==3|q312co_4==4|q312co_4==7|q312co_4==9|q312co_4==12)
gen know_health = (q312co_5==1|q312co_5==3|q312co_5==4|q312co_5==9|q312co_5==11|q312co_5==12)


*Contacted officials

gen contact_water=(q312co_1!=.)
gen contact_roads=(q312co_2!=.)
gen contact_elec=(q312co_3!=.)
gen contact_educ=(q312co_4!=.)
gen contact_health=(q312co_5!=.)


*Contacted Sarpanch

gen sarpanch_water=(q312co_1==1)
gen sarpanch_roads=(q312co_2==1)
gen sarpanch_elec=(q312co_3==1)
gen sarpanch_educ=(q312co_4==1)
gen sarpanch_health=(q312co_5==1)


*Priorities

gen issue_water = (Q34s_1==1 | Q34s_2==1 | Q34s_3==1)
gen issue_roads = (Q34s_1==3 | Q34s_2==3 | Q34s_3==3) 
gen issue_elec = (Q34s_1==4 | Q34s_2==4 | Q34s_3==4) 
gen issue_educ = (Q34s_1==5 | Q34s_2==5 | Q34s_3==5) 
gen issue_health = (Q34s_1==6 | Q34s_2==6 | Q34s_3==6) 


*Public Goods Quality

gen WaterQual = 0
replace WaterQual = 1 if q31_a > 2
replace WaterQual = . if q31_a==.|q31_a==9

gen RoadsQual = 0
replace RoadsQual = 1 if q31_h > 2
replace RoadsQual = . if q31_h==.|q31_h==9

gen ElecQual = 0
replace ElecQual = 1 if q31_d > 2
replace ElecQual = . if q31_d==.|q31_d==9

gen EducQual = 0
replace EducQual = 1 if q31_f > 2
replace EducQual = . if q31_f==.|q31_f==9

gen HealthQual = 0
replace HealthQual = 1 if q31_c > 2
replace HealthQual = . if q31_c==.|q31_c==9



*Water Infrastructure

gen PipedWater = 0
replace PipedWater = 1 if q310==1|q310==2|q310==3
replace PipedWater = . if q310==.
replace PipedWater = . if q310==99
label var PipedWater "Access to piped water"

gen NoSafeWater = 0
replace NoSafeWater = 1 if q310>15
replace NoSafeWater = . if q310==.
replace NoSafeWater = . if q310==99
label var NoSafeWater "Unprotected water source only"

gen FarmWater = 0
replace FarmWater = 1 if Q48_1==3
label var FarmWater "Water for irrigation"


* Decision Making
 
gen FinalSay_Sch=(q66_1==1) 
label var FinalSay_Sch "Final say: children's schooling"
gen FinalSay_Med=(q66_2==1) 
label var FinalSay_Med "Final say: medical decisions"
gen FinalSay_FP=(q66_3==1) 
label var FinalSay_FP "Final say: family-planning"


*Voting

gen VoteLocal=(q712_1==1 | q712_1==2)
label var VoteLocal "Generally vote in local elections"
gen VoteState=(q712_2==1 | q712_2==2)
label var VoteState "Generally vote in state elections"
gen VoteNational=(q712_3==1 | q712_3==2)
label var VoteNational "Generally vote in national elections"


*Borrowing and Saving

gen BankLoan=(q59==1)
label var BankLoan "Received a bank loan in the past 5 years" 
gen SavingHabit=(q51==1)
label var SavingHabit "In the habit of saving" 


* Gram Sabha/Gram Panchayat
gen GS_EvrAttd=(q77==1)
label var GS_EvrAttd "Attended Gram Sabha"
gen GS_FreqAttd=q78
gen GP_Interact=(q75==1)
label var GP_Interact "Interacted with Gram Panchayat"
gen EngageGSGP = (GS_EvrAttd==1 & GP_Interact==1)
replace EngageGSGP = . if q74==.
label var EngageGSGP "Contacted Gram Sabha or Gram Panchayat" 


* Controls

gen HHead = 0
replace HHead = 1 if q12_1 ==1
replace HHead = . if q12_1 ==.
label var HHead "Respondent is head of household"

gen Age=q15_1 if q13_1==1 | q13_1==99   
replace Age=q15_2 if q13_2==1 
replace Age=q15_3 if q13_3==1 
replace Age=q15_4 if q13_4==1 
replace Age=q15_5 if q13_5==1 
replace Age=q15_6 if q13_6==1 
replace Age=q15_7 if q13_7==1 

gen Literate=1 if (q16_1>=2 & q16_1<=7) & q13_1==1 | q13_1==99   
replace Literate=1 if q13_2==1 & q13_2==1 
replace Literate=1 if q13_3==1 & q13_3==1 
replace Literate=1 if q13_4==1 & q13_4==1 
replace Literate=1 if q13_5==1 & q13_5==1 
replace Literate=1 if q13_6==1 & q13_6==1 
replace Literate=1 if q13_7==1 & q13_7==1 
replace Literate=0 if (q16_1==1 | q16_1>7) & q13_1==1 | q13_1==99   
replace Literate=0 if (q16_2==1 | q16_2>7) & q13_2==1 
replace Literate=0 if (q16_3==1 | q16_3>7) & q13_3==1 
replace Literate=0 if (q16_4==1 | q16_4>7) & q13_4==1 
replace Literate=0 if (q16_5==1 | q16_5>7) & q13_5==1 
replace Literate=0 if (q16_6==1 | q16_6>7) & q13_6==1 
replace Literate=0 if (q16_7==1 | q16_7>7) & q13_7==1 

gen Child1=(q15_1<=14)
gen Child2=(q15_2<=14)
gen Child3=(q15_3<=14)
gen Child4=(q15_4<=14)
gen Child5=(q15_5<=14)
gen Child6=(q15_6<=14)
gen Child7=(q15_7<=14)
gen Child8=(q15_8<=14)
gen Child9=(q15_9<=14)
gen Child10=(q15_10<=14)
gen Child11=(q15_11<=14)
gen Child12=(q15_12<=14)
gen Child13=(q15_13<=14)

gen Children = Child1+Child2+Child3+Child4+Child5+Child6+Child7+Child8+Child9+Child10+Child11+Child12+Child13
label var Children  "Number of children below age 14" 

gen Married=(q17_1==1)

gen SC=(q114==1)
label var SC "Scheduled caste"

gen ST=(q114==2)
label var ST "Scheduled tribe"

gen Landowner = (Q41_1==1 | Q41_1==2 | Q41_2==1 | Q41_2==2)
label var Landowner "Owns land" 

gen Kutcha=(q115==1)
label var Kutcha "Non-permanent dwelling" 



